/*
 www.pipoisu.com
 Copyright (c) 2011.  All rights reserved.

 File     : i2cmaster.h
 Author(s): Erez Raviv

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _I2CMASTER_H
#define _I2CMASTER_H   1

//#include <avr/io.h>
#include <inttypes.h>


#define I2C_READ    1
#define I2C_WRITE   0


//  initialize the I2C master interace. Need to be called only once
void i2c_init();

//  Terminates the data transfer and releases the I2C bus
void i2c_stop();


// Issues a start condition and sends address and transfer direction
unsigned char i2c_start(unsigned char addr);


// Issues a repeated start condition and sends address and transfer direction
//unsigned char i2c_rep_start(unsigned char addr);

// Issues a start condition and sends address and transfer direction
//void i2c_start_wait(unsigned char addr);

// Send one byte to I2C device
// data  byte to be transfered
// 0 write successful
// 1 write failed
unsigned char i2c_write(unsigned char data);

// read one byte from the I2C device, request more data from device
unsigned char i2c_readAck();

// read one byte from the I2C device, read is followed by a stop condition
unsigned char i2c_readNak();

void i2cWrite(uint8_t addr, uint8_t reg, uint8_t val);
uint8_t i2cRead(uint8_t addr, uint8_t reg);
uint8_t i2cDeviceReady(uint8_t addr);
void i2cRead6(uint8_t addr, uint8_t reg, uint8_t * t);


/**@}*/
#endif
